package com.admin.business.venusOaBarriers;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 道闸
 * @create: 2022-03-28 14:31:02
 **/
@Service("venusOaBarriers")
@Slf4j
public class VenusOaBarriersService{

    @Resource
    VenusOaBarriersDao venusOaBarriersDao;

    /**
     * 添加道闸,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - user_id:操作人id
     *                   - dz_code:编码
     *                   - mac_addr:MAC地址
     *                   - dz_edition:道闸版本
     *                   - dz_name:名称
     *                   - ip_addr:ip地址
     *                   - mj_factory:门禁厂家
     *                   - parking_lot:停车场
     *                   - mj_direction:门禁方向
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:删除，0正常1删除
     * @return
     * @author ht
     * @create: 2022-03-28 14:31:02
     */
    @OpenApi
    public Return addVenusOaBarriers(CDO cdoRequest) {
        venusOaBarriersDao.addVenusOaBarriers(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新道闸数据
     *
     * @param cdoRequest - id:主键
     *                   - user_id:操作人id
     *                   - dz_code:编码
     *                   - mac_addr:MAC地址
     *                   - dz_edition:道闸版本
     *                   - dz_name:名称
     *                   - ip_addr:ip地址
     *                   - mj_factory:门禁厂家
     *                   - parking_lot:停车场
     *                   - mj_direction:门禁方向
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:删除，0正常1删除
     * @return
     * @author ht
     * @create: 2022-03-28 14:31:02
     */
    @OpenApi
    public Return updateVenusOaBarriersById(CDO cdoRequest) {
        int affectedRows = venusOaBarriersDao.updateVenusOaBarriersById(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，删除道闸数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author ht
     * @create: 2022-03-28 14:31:02
     */
    @OpenApi
    public Return deleteVenusOaBarriersById(CDO cdoRequest){
        int affectedRows = venusOaBarriersDao.deleteVenusOaBarriersById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除道闸数据
     *
     * @param cdoRequest
     * @return
     * @author ht
     * @create: 2022-03-28 14:31:02
     */
    @OpenApi
    public Return deleteVenusOaBarriers(CDO cdoRequest) {
        int affectedRows = venusOaBarriersDao.deleteVenusOaBarriers(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取道闸数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author ht
     * @create: 2022-03-28 14:31:02
     */
    @OpenApi
    public Return getVenusOaBarriersById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaBarriersDao.getVenusOaBarriersById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据混合条件，获取道闸数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author ht
     * @create: 2022-03-28 14:31:02
     */
    @OpenApi
    public Return getVenusOaBarriers(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaBarriersDao.getVenusOaBarriers(cdoRequest);
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取道闸数据列表
     *
     * @param cdoRequest
     * @return
     * @author ht
     * @create: 2022-03-28 14:31:02
     */
    @OpenApi
    public Return getVenusOaBarriersList(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaBarriersDao.getVenusOaBarriersList(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaBarriersDao.getVenusOaBarriersListCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据混合条件，获取道闸数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author ht
     * @create: 2022-03-28 14:31:02
     */
    @OpenApi
    public Return getVenusOaBarriersListByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaBarriersDao.getVenusOaBarriersListByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaBarriersDao.getVenusOaBarriersListByConditionCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
